﻿#pragma once

class FileHelper
{
public:
  FileHelper();
  ~FileHelper();

  static void relaPath2FullPath(const char* const& rPath, std::string& fullPath ) {
    //filePathbuf变量是保存着相对路径的char型数组,dir用来保存绝对路径
    char dir[1024] = "";
//1.转换绝对路径到dir
#ifdef _WIN32
    _fullpath(dir, rPath, 1024);
#else
    realpath(rPath, dir);
#endif
    //2.替换绝对路径中的'/'为'\'
    //因为上述方法转换出来的绝对路径之间会以'/'分隔，例如“C:/user/desktop”,字符串处理遇到'/'一般会报错，下面一行代码将'/'全部替换为'\'
    for (int i = 0; dir[i] != 0 && i < 1024; i++)
    {
      if (dir[i] == 92)
      {
        dir[i] = '/';
      }
    }

    fullPath = dir;
  }


private:
};

FileHelper::FileHelper() {}

FileHelper::~FileHelper() {}